import prompt from '@system.prompt';
import router from '@system.router';
export default {
    data: {
        id: -1,             // 当前公交Id
        totalWidth: 780,     // 总距离 stationDetail.length * stationWidth
        stationWidth: 60,   // 车站距离
        stationDetail: [
            {"stationName": "海珠客运站总站", "parentId": 1, "displayOrder": 1, "parentName":"987路", "startStation": "海珠客运站总站", "endStation": "天安科技园总站",}
            ,{"stationName": "三滘村", "parentId": 1, "displayOrder": 2},
            {"stationName": "沥滘", "parentId": 1, "displayOrder": 3},
            {"stationName": "后滘村", "parentId": 1, "displayOrder": 4},
            {"stationName": "沙溪村", "parentId": 1, "displayOrder": 5},
            {"stationName": "星河湾", "parentId": 1, "displayOrder": 6},
            {"stationName": "塘步西", "parentId": 1, "displayOrder": 7},
            {"stationName": "南大路口", "parentId": 1, "displayOrder": 8},
            {"stationName": "华南碧桂园", "parentId": 1, "displayOrder": 9},
            {"stationName": "里仁洞", "parentId": 1, "displayOrder": 10},
            {"stationName": "冼庄立交", "parentId": 1, "displayOrder": 11},
            {"stationName": "万博翠湖花园", "parentId": 1, "displayOrder": 12},
            {"stationName": "天安科技园总站", "parentId": 1, "displayOrder": 13}
        ],                         // 车站详细信息
        currentPercent: 25,        // 当前进度 currentStation=3
        secondaryPercent: 41.6,    // 候车进度 waitingStation=5
        currentStation: 4,         // 当前车站
        waitingStation: 6          // 距离候车站数
    },
    onInit() {
        this.getStationList();
    },
    initAction: function (code) {
        let actionData = {"parentId": this.id};
        let action = {};
        action.bundleName = "com.army.study";
        action.abilityName = "com.army.study.service.BusInternalAbility";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
    getStationList: async function () {
        try {
            var action = this.initAction(1002);
            var result = await FeatureAbility.callAbility(action);
            console.info(" @@result = " + JSON.stringify(result));

            this.stationDetail = JSON.parse(result);
            this.totalWidth = this.stationDetail.length * this.stationWidth;

            var _basePercent = this.stationWidth / ((this.stationDetail.length-1) * this.stationWidth / 100);
            this.currentPercent = _basePercent * this.currentStation;
            this.secondaryPercent = _basePercent * this.waitingStation;

            console.log("End");

        } catch (pluginError) {
            console.error("getStationList : Plugin Error = " + pluginError);
        }
    },
    onBack() {
        router.push({
            uri: "pages/index/index"
        });
    }
}
